package urban.view;

import model.User;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import controller.WebClientInterface;

public class UrbanViewActivityLayout01 extends Activity {
	EditText login;
	EditText senha;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loguinlayout);
		login = (EditText)findViewById(R.id.campoUsuario);
		senha = (EditText)findViewById(R.id.campoSenha);
		
		Button cadastrar = (Button) findViewById(R.id.buttonCadastrar);
		
		
	
		cadastrar.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(UrbanViewActivityLayout01.this, UrbanViewActivityCadastrar.class);
				startActivityForResult(i, 1);
				//setContentView(R.layout.cadastrarlayout);
				
			}
		});
		
		Button logar = (Button) findViewById(R.id.buttonLogin);
		logar.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
//					Intent i = new Intent( UrbanViewActivityLayout01.this, UrbanViewActivityLogado.class);
					String email = login.getText().toString();
					User user = WebClientInterface.readUser(email);
//					System.out.println(login.getContentDescription());
					if(user != null)
					{
						if(user.getLogin().equals(email) && user.getPassword().equals(senha.getText().toString()))
						{
							
							Bundle b=new Bundle();
							b.putString("email", email);
							Intent i= new Intent( UrbanViewActivityLayout01.this, UrbanViewActivityLogado.class);
							i.putExtras(b);
							
							startActivityForResult(i, 1);
						}
						else
						{
							makeText("Usuario ou senha incorretos!");
						}
					}
					else
					{
						makeText("Usuario inexistente!");
					}
								
			}
		});
		
		
		
		/*botao.setOnClickListener(new View.OnClickListener() {
		    public void onClick(View v) {
		    }
		});*/
		 
		//
		//startActivityForResult(butao, R.layout.loguinlayout);
		
	}
	
	private void makeText(String str)
	{
		Toast.makeText(this, str, Toast.LENGTH_LONG).show();
	}
	
	
	

}
